package com.redis.seckill.controller;


import com.redis.seckill.dao.OrderDao;
import com.redis.seckill.entity.MyOrder;
import com.redis.seckill.lang.Renum;
import com.redis.seckill.lang.Result;
import com.redis.seckill.mq.service.Sender;
import com.redis.seckill.service.MyOrderService;
import com.redis.seckill.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @since 2020-10-28
 */
@RestController
@RequestMapping("/order")
public class MyOrderController {


    @Autowired
    private MyOrderService myOrderService;

    /**
     * 下单
     * @param productId
     * @param userId
     * @param quantity
     */
    @RequestMapping("/create")
    public Result demo(Integer userId,Integer productId,Integer quantity){
        userId = 1;
        productId = 1;
        quantity = 1;
        boolean seckill = myOrderService.seckill(userId, productId, quantity);
        if (!seckill){
            return ResultUtil.fail(Renum.BUY_FAIL.getCode(),Renum.BUY_FAIL.getMsg());
        }
        return ResultUtil.success(Renum.BUY_SUCCESS.getCode(),Renum.BUY_SUCCESS.getMsg());
    }

}
